//
//  MemberListView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/23.
//

#import "MemberListView.h"
#import "MemberCell.h"
#import "CommonUtil.h"

@interface MemberListView ()<UITableViewDataSource,UITableViewDelegate>


@property (strong, nonatomic) UIButton * selectBtn;
@property (strong, nonatomic) UIButton * personSortBtn;
@property (strong, nonatomic) UIButton * numberSortBtn;
@property (strong, nonatomic) UIButton * resultBtn;

@property (strong, nonatomic) UITableView * tableView;

@end

@implementation MemberListView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.personSortBtn];
        [self addSubview:self.numberSortBtn];
        [self addSubview:self.resultBtn];
        [self addSubview:self.tableView];
        
        [self sortBtnClick:self.numberSortBtn];
    }
    return self;
}


#pragma mark - UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MemberCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [cell refreshWithData:indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return AD(160);
}


- (void)sortBtnClick:(UIButton *)sender{
    self.selectBtn.selected = false;
    self.selectBtn = sender;
    self.selectBtn.selected = YES;
}

- (void)copyBtnClick:(UIButton *)sender{
    NSLog(@"复制结果");
}

#pragma mark - lazy

-(UIButton *)personSortBtn{
    if (!_personSortBtn) {
        _personSortBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_personSortBtn setTitle:@"按人数排序" forState:UIControlStateNormal];
        [_personSortBtn setImage:[UIImage imageNamed:@"statistics_normal"] forState:UIControlStateNormal];
        [_personSortBtn setImage:[UIImage imageNamed:@"statistics_select"] forState:UIControlStateSelected];
        [_personSortBtn addTarget:self action:@selector(sortBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _personSortBtn.frame = CGRectMake(AD(5), AD(10), AD(90), AD(30));
        [_personSortBtn setTitleColor:RGB(168.0, 168.0, 168.0) forState:UIControlStateNormal];
        _personSortBtn.titleLabel.font = [UIFont systemFontOfSize:AD(11)];
    }
    return _personSortBtn;
}


-(UIButton *)numberSortBtn{
    if (!_numberSortBtn) {
        _numberSortBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_numberSortBtn setTitle:@"按号码排序" forState:UIControlStateNormal];
        [_numberSortBtn setImage:[UIImage imageNamed:@"statistics_normal"] forState:UIControlStateNormal];
        [_numberSortBtn setImage:[UIImage imageNamed:@"statistics_select"] forState:UIControlStateSelected];
        [_numberSortBtn addTarget:self action:@selector(sortBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _numberSortBtn.frame = CGRectMake(_personSortBtn.right + AD(0), AD(10), AD(90), AD(30));
        [_numberSortBtn setTitleColor:RGB(168.0, 168.0, 168.0) forState:UIControlStateNormal];
        _numberSortBtn.titleLabel.font = [UIFont systemFontOfSize:AD(11)];
    }
    return _numberSortBtn;
}

-(UIButton *)resultBtn{
    if (!_resultBtn) {
        _resultBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_resultBtn setTitle:@"复制结果" forState:UIControlStateNormal];
        [_resultBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _resultBtn.backgroundColor = RGB(197.0, 197.0, 197.0);
        _resultBtn.titleLabel.font = [UIFont systemFontOfSize:AD(12)];
        [_resultBtn addTarget:self action:@selector(copyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _resultBtn.layer.cornerRadius = AD(5);
        _resultBtn.clipsToBounds = YES;
        _resultBtn.frame = CGRectMake(_numberSortBtn.right + AD(20), AD(10), AD(80), AD(30));
    }
    return _resultBtn;
}


-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, _personSortBtn.bottom+AD(10), self.width, self.height-_personSortBtn.bottom)];
        [_tableView registerClass:[MemberCell class] forCellReuseIdentifier:@"cell"];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.contentInset =UIEdgeInsetsMake(0, 0, AD(10), 0);
    }
    return _tableView;
}
@end
